package com.dtz.rabbitmq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.dtz.rabbitmq.constant.RabbitConstant;


/**
 * 消息队列配置
 * @author 陶志胜
 *
 */
@Configuration
public class FanoutConfiguration {
	

	/**
	 * 定义交换机
	 * @return
	 */
	@Bean
	public FanoutExchange getFanouExchange() {
		return new FanoutExchange(RabbitConstant.FANTOU_ORDER_EXCHANGE, true, false, null);
	}
	
	/**
	 * 定义消息队列
	 * @return
	 */
	@Bean
	public Queue emailQueue() {
		return new Queue(RabbitConstant.FANTOU_EMAIL_QUEUE, true);
	}
	
	@Bean
	public Queue smsQueue() {
		return new Queue(RabbitConstant.FANTOU_SMS_QUEUE, true);
	}
	
	@Bean
	public Queue duanxinQueue() {
		return new Queue(RabbitConstant.FANTOU_DUANXIN_QUEUE, true);
	}
	
	/**
	 * 将消息队列与交换机绑定
	 * @return
	 */
	@Bean
	public Binding fanoutEmailBinding() {
		return BindingBuilder.bind(emailQueue()).to(getFanouExchange());
	}
	
	@Bean
	public Binding fanoutSmsBinding() {
		return BindingBuilder.bind(smsQueue()).to(getFanouExchange());
	}
	
	@Bean
	public Binding fanoutDuanxinBinding() {
		return BindingBuilder.bind(duanxinQueue()).to(getFanouExchange());
	}
	
}
